package com.zl.customribbon.controller;

import com.zl.common.model.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhouliang
 * @date 2019/12/9 11:28
 */
@Slf4j
@RestController
@RequestMapping("/custom")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomController {
    private final RestTemplate restTemplate;

    /**
     * 测试restTemplate的负载均衡
     *
     * @return User
     */
    @GetMapping(value = "/testRestTemplateLoadBalanced", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public User testRestTemplateLoadBalanced() {
        String url = "http://provider-ribbon/provider/findUserById/{id}";
        return restTemplate.getForObject(url, User.class, 1L);
    }

}
